﻿using System;
using System.Collections;
using System.Web.Security;
using Tecnopez.Globals;

public partial class GenericMasterPage : System.Web.UI.MasterPage
{
    public string Titulo
    {
        get { return lblMasterTitulo.Text; }
        set { lblMasterTitulo.Text = value;
                this.Page.Title=string.Format("TecnoPez - {0}", value);
            }
    }

    public string Imagen 
    {
        get { return imgMasterImage.ImageUrl; }
        set { imgMasterImage.ImageUrl = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack==false)
        {
            this.Estilo.Href = string.Format("{0}Styles/StyleSheetTecnoPez.css", Functions.getHost(this.Page));
        }
        lblFechaDeHoy.Text = DateTime.Now.ToString("dd' de 'MMMM' de 'yyyy");
    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        if (Session["KEY_HASH"] == null)
            return;
        Hashtable objHash = Application[Session["KEY_HASH"].ToString()] as Hashtable;
        if (objHash == null)
        {
            Server.Transfer("~/login.aspx");
        }
        else
        {
            string[] strUrlPage = this.Page.Request.Url.AbsoluteUri.Split('?');

            string strPage = objHash[strUrlPage[0].ToUpper()] as string;
            if (strPage == null)
            {
                //Response.Redirect("~/Error.aspx");
                Server.Transfer("~/Error.aspx");
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.Estilo.Href == "")
        {
            this.Estilo.Href = "../Styles/StyleSheetTecnoPez.css";
        }
        else
        {
            this.Estilo.Href = "";
        }
    }
    protected void loginStatus_LoggedOut(object sender, EventArgs e)
    {
        //Response.Redirect("~/Default.aspx");
        //Session.Clear();
        //Session.Abandon();
        FormsAuthentication.SignOut();
        Session.Clear();
        Response.Redirect( Functions.getHost(this.Page));
    }
}
